<template>
    <div class="observerLibrary-increase">
        <!-- 新增弹窗 -->
        <a-modal
         :visible="visibleShow" 
         class="enterpriseInformation-modal"
         width="1000px"
         title="查看企业信息" 
         @ok="visibleShow = false" 
         :confirmLoading="confirmLoading"
         @cancel="visibleShow = false">

            <a-form layout="inline" v-if="visibleShow" :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" >
                <a-form-item label="企业名称">
                    {{ formState.fqymc }}
                </a-form-item>
                <a-form-item label="企业法定代表人/负责人">
                    {{ formState.fqyfddbrfzr }}
                </a-form-item>
                <a-form-item label="企业联系人">
                    {{ formState.fqylxr }}
                </a-form-item>
                
                <a-form-item label="企业联系人电话">
                    {{ formState.fqylxrdh }}
                </a-form-item>
                <a-form-item label="企业联系人邮箱">
                    {{ formState.fqylxryx }}
                </a-form-item>
                <a-form-item label="所在地区">
                    {{ formState.fszdq }}
                </a-form-item>
                <div style="border-top: 1px solid rgb(233 228 228);margin: 10px 0;"/>
                <!-- ------------------- -->
                <a-form-item label="企业许可证号">
                    {{ formState.fqyxkzh }}
                </a-form-item>
                <a-form-item label="企业许可证有效期">
                    {{ formState.fqyxkzyxq }}
                </a-form-item>
                <a-form-item label="统一社会信用代码">
                    {{ formState.ftyshxydm }}
                </a-form-item>
                <a-form-item label="企业住所/注册地址">
                    {{ formState.fqyzszcdz }}
                </a-form-item>
                <a-form-item label="详细地址">
                    {{ formState.fxxdz }}
                </a-form-item>
                <a-form-item label="行政机构">
                    {{ formState.fxzjg }}
                </a-form-item>
            </a-form>
            
        </a-modal>
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import compSelector from '@/components/compSelector/compSelector'
import validator from '@/common/validator'
import {addServe, editServe,ocalityPostAction} from './service/index'
export default {
    components:{
        compSelector
    },
    props:{
        addEditParameter:{
            type:Object,
            default:[]
        }
    },
    data(){
        return{
            form: this.$form.createForm(this, { name: 'coordinated' }),
            visibleShow:false,
            confirmLoading:false,
            typeSelect:typeSelect,
            formState:{},
            rules:{
                fqyfddbrfzr: [{
                    required: true,
                    message: '请输入企业法定代表人/负责人',
                    trigger: 'blur',
                }],
                fqylxr: [{
                    required: true,
                    message: '请输入企业联系人',
                    trigger: 'blur',
                }],
                fqylxrdh: [{
                    required: true,
                    message: '请输入企业联系人电话',
                    trigger: 'blur',
                }],
                fszdq: [{
                    required: true,
                    message: '请选择所在地区',
                    trigger: 'blur',
                }],
                fqylxryx:[{
                    required: true,
                    message: '请输入企业联系人邮箱',
                    trigger: 'blur',
                },{
                    pattern: validator.isEmail.reg,
                    message: '请输入正确的企业联系人邮箱',
                    trigger: 'blur',
                }],
                fqymc: [{
                    required: true,
                    message: '请输入企业名称',
                    trigger: 'blur',
                }],
                fqyxkzh: [{
                    required: true,
                    message: '请输入企业许可证号',
                    trigger: 'blur',
                }],
                fqyxkzyxq: [{
                    type:'object',
                    required: true,
                    message: '请输入企业许可证有效期',
                    trigger: 'blur',
                }],
                fqyzszcdz: [{
                    required: true,
                    message: '请输入企业住所/注册地址',
                    trigger: 'blur',
                }],
                ftyshxydm: [{
                    required: true,
                    message: '请输入统一社会信用代码',
                    trigger: 'blur',
                }],
                fxxdz: [{
                    required: true,
                    message: '请输入详细地址',
                    trigger: 'blur',
                }],
                fxzjg: [{
                    required: true,
                    message: '请输入行政机构',
                    trigger: 'blur',
                }],
            },
            formRequer:'',
            optionsArr:[],
            submittedSuccessfully:false,
        }
    },
    watch:{
        addEditParameter(newval,oldVal){
            //console.log('给了什么啊',newval)
            this.formState = newval
        }
    },
    mounted(){
        ocalityPostAction({dictName:'观察员所属地市'}).then(res=>{
                //console.log('字典的res',res)
                if(res.code == 200){
                    if(res.result.length){
                        this.optionsDataChange(res.result,{label:'itemText',value:'itemValue'})
                    }
                    
                }
            })
    },
    updated(){
        this.$emit('updatedSuccess')
    },
    methods:{
        optionsDataChange(dataList,dataType){
            var newOptionArr = []
            //标识每一项的下标，并且添加到每一项
            dataList.forEach((item,index) => {
                 
                //console.log(newOptionArr.filter(l=>l.itemIndex === index))
                if(!newOptionArr.filter(l=>l.itemIndex === index).length){
                    newOptionArr.push({...item,itemIndex:index})
                }
            });
            //console.log('这是有下标的数组',newOptionArr)
            for (let i = 0; i <= newOptionArr.length; i++) {//打印的item为数组中的每一个对象
                let item = newOptionArr[i]
                let index = i
                for (let key in item) { //遍历数组中的对象
                    var currentItem = {}
                    //console.log(index)
                     
                    if(index === item.itemIndex){
                        currentItem = {
                            label:item[dataType.label],
                            value:item[dataType.value]
                        }
                        
                        if(!this.optionsArr.filter(l=>l.label === currentItem.label).length && currentItem.label){
                            this.optionsArr.push(currentItem)
                        }
                    }
                    

                }
            }
            //console.log('当前获取到的optionArr',this.optionsArr)
        },
        
    }

}

</script>
<style lang="less">
/* .ant-form-item-label{
    font-weight: 600;
} */

 .ant-modal-title{
    font-weight: 600;
 }
 .ant-modal-header{
    background: #5ca3e5;
 }
 .ant-upload-list{
    display: none !important;
 }
 .ant-modal-footer .ant-btn-primary{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
 }
 .enterpriseInformation-modal{
    .ant-form-item-label{
        width: 175px;
    }
    .ant-form-item-control-wrapper{
        width: 260px;
    }
    .ant-calendar-picker{
        width: 260px;
    }
 }
</style>